<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 6.0.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/ficon.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/icon.png">
  <link rel="mask-icon" href="/images/icon.png" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
  <link rel="stylesheet" href="/lib/pace/pace-theme-minimal.min.css">
  <script src="/lib/pace/pace.min.js"></script>

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"bqlin.github.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":true,"comments":{"style":"tabs","active":"gitalk","storage":true,"lazyload":false,"nav":{"gitalk":{"order":-2}},"activeClass":"gitalk"},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":-1,"unescape":false,"preload":false},"motion":{"enable":false,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="Object File object file是个有结构的位元块。这些位元块包含程序代码】准备给Linker和Loader使用的相关信息。">
<meta property="og:type" content="article">
<meta property="og:title" content="静态库与动态库">
<meta property="og:url" content="https://bqlin.github.io/posts/static_lib_vs_and_dynamic_lib/index.html">
<meta property="og:site_name" content="權咚领域">
<meta property="og:description" content="Object File object file是个有结构的位元块。这些位元块包含程序代码】准备给Linker和Loader使用的相关信息。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/bqlin/image-land/raw/master/mach-o.png">
<meta property="og:image" content="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/art/address_space1_2x.png">
<meta property="og:image" content="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/art/address_space2_2x.png">
<meta property="article:published_time" content="2019-09-09T06:20:52.000Z">
<meta property="article:modified_time" content="2019-09-09T06:20:52.000Z">
<meta property="article:author" content="權咚">
<meta property="article:tag" content="Apple">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/bqlin/image-land/raw/master/mach-o.png">

<link rel="canonical" href="https://bqlin.github.io/posts/static_lib_vs_and_dynamic_lib/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>静态库与动态库 | 權咚领域</title>
  
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-105338942-1"></script>
    <script>
      if (CONFIG.hostname === location.hostname) {
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'UA-105338942-1');
      }
    </script>


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?98fcf61fd269408d07dcbc1e49311f9a";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

<link rel="alternate" href="/atom.xml" title="權咚领域" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">權咚领域</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">Making app a work of art.</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://bqlin.github.io/posts/static_lib_vs_and_dynamic_lib/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/icon.png">
      <meta itemprop="name" content="權咚">
      <meta itemprop="description" content="🤘🤯👾">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="權咚领域">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          静态库与动态库
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2019-09-09 14:20:52" itemprop="dateCreated datePublished" datetime="2019-09-09T14:20:52+08:00">2019-09-09</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/iOS/" itemprop="url" rel="index"><span itemprop="name">iOS</span></a>
                </span>
            </span>

          
            <span class="post-meta-item" title="阅读次数" id="busuanzi_container_page_pv" style="display: none;">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span id="busuanzi_value_page_pv"></span>
            </span><br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="far fa-file-word"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>3.5k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="far fa-clock"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>3 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="object-file">Object File</h2>
<p>object file是个有结构的位元块。这些位元块包含程序代码】准备给Linker和Loader使用的相关信息。</p>
<p>查看object file：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">objdump -macho -section-headers /bin/ls</span><br></pre></td></tr></table></figure>
<p>object file的形式：</p>
<ul>
<li>Relocatable：包含可以在编译时被其他Relocatable链接的代码和数据，以生成Executable。多个Relocatable可被封装成.a（archive）静态库（static library、static archive）。</li>
<li>Executable：可以载入内存的执行的指令集合。链接器会把静态库中的代码给定一个固定的load地址，并包含（copies and relocates）进Executable中。且每个Executable使用静态库都要拷贝一份静态库。</li>
<li>Shared：一种特殊形式的Relocatable，类似动态库。不并入任何Executable，可在多个Executable之间共享。</li>
<li>Bundle：在macOS中长作为插件使用。</li>
</ul>
<h3 id="macos支持的可执行格式">macOS支持的可执行格式</h3>
<table>
<colgroup>
<col style="width: 11%" />
<col style="width: 36%" />
<col style="width: 51%" />
</colgroup>
<thead>
<tr class="header">
<th>可执行格式</th>
<th>magic</th>
<th>用途</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>脚本</td>
<td><code>\x7FELF</code></td>
<td>主要用于 shell 脚本，但是也常用语其他解释器，如 Perl, AWK 等。也就是我们常见的脚本文件中在 <code>#!</code> 标记后的字符串，即为执行命令的指令方式，以文件的 stdin 来传递命令</td>
</tr>
<tr class="even">
<td>通用二进制格式</td>
<td><code>0xcafebabe</code> <code>0xbebafeca</code></td>
<td>包含多种架构支持的二进制格式，只在 macOS 上支持</td>
</tr>
<tr class="odd">
<td>Mach-O</td>
<td><code>0xfeedface</code>（32 位） <code>0xfeedfacf</code>（64 位）</td>
<td>macOS 的原生二进制格式</td>
</tr>
</tbody>
</table>
<h3 id="通用二进制格式">通用二进制格式</h3>
<p>通用二进制格式（Universal Binary、Fat Binary）。Apple提出这个是为了解决一些历史问题。macOS，更确切地说是OS X，最早是基于PPC架构的，后来才移植到Intel架构（OSX Tiger 10.4.7开始），通用二进制格式可以在PPC和x86两种处理器上执行。即，对多架构二进制文件的打包集合文件。</p>
<p>macOS的多架构二进制文件就是适配不同架构的Mach-O文件。</p>
<h3 id="mach-o">Mach-O</h3>
<p>Mach-O（Mach Object File Format）是苹果平台OS上的可执行文件格式，类似于Linux和大部分UNIX的原声格式ELF（Extensible Firmware Interface）。</p>
<h4 id="文件格式">文件格式</h4>
<figure>
<img src="https://gitee.com/bqlin/image-land/raw/master/mach-o.png" alt="mach-o" /><figcaption aria-hidden="true">mach-o</figcaption>
</figure>
<p>Mach-O格式主要由以下3部分组成：</p>
<ul>
<li>Mach-O头（Mach-O Header）：描述了Mach-O的CPU架构、文件类型、加载命令等信息。</li>
<li>加载命令（Load Command）：描述了文件中数据的具体组织结构，不同的数据类型使用不同的加载命令表示。</li>
<li>数据（Data）：存储每个段（Segment）的数据。段拥有一个或多个Section，存储数据和代码，与ELF文件中的段类似。</li>
</ul>
<h3 id="参考">参考</h3>
<ul>
<li><a target="_blank" rel="noopener" href="https://www.desgard.com/iOS-Source-Probe/C/mach-o/Mach-O%20%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F%E6%8E%A2%E7%B4%A2.html">Mach-O 文件格式探索 · GitBook</a></li>
<li><a target="_blank" rel="noopener" href="http://satanwoo.github.io/2017/06/13/Macho-1/">深入剖析Macho (1) | SatanWoo</a></li>
<li><a target="_blank" rel="noopener" href="https://objccn.io/issue-6-3/">ObjC 中国 - Mach-O 可执行文件</a></li>
</ul>
<h2 id="静态库">静态库</h2>
<p>静态库（Static Libraries），多个目标文件（object file）的打包集合。</p>
<p>特点：</p>
<ul>
<li>静态库会直接嵌入到App的Mach-O中。</li>
<li>编译时已经链接，启动时不需要二次查找。因此App启动更快。</li>
<li>每个Executable使用都要拷贝一份静态库。</li>
</ul>
<figure>
<img src="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/art/address_space1_2x.png" alt="图1 使用静态库的应用" /><figcaption aria-hidden="true">图1 使用静态库的应用</figcaption>
</figure>
<h3 id="构建设置">构建设置</h3>
<ul>
<li>Linking-Math-O Type: Static Library</li>
<li>Dead Code Stripping: No</li>
</ul>
<h2 id="动态库">动态库</h2>
<p>动态库（动态链接库、Dynamic Libraries、Shared Library、Shared Object），同样也是目标文件的集合，与静态库区别的是嵌入App的方式和在App加载的方式。</p>
<p>特点：</p>
<ul>
<li>以独立文件嵌入App包中。</li>
<li>App的Mach-O中只包含其引用信息，使用的时候才进行动态链接和加载。可在两个时机载入，并动态分配一段地址：
<ul>
<li>App载入时（load time）：启动时加载，称为动态链接库。</li>
<li>App运行时（run time）：启动后加载，称为动态加载库。</li>
</ul></li>
<li>多个Executable使用都不会进行拷贝。可独立更新。</li>
</ul>
<p>只有系统库或在macOS上的动态库才有以上自由选择载入时机的特性，在iOS中，只能通过Embedding Frameworks的方式使用动态库，并在启动时载入与链接动态库。而其链接动态库也是造成启动时间长的原因。</p>
<p>在iOS的多个Executable可以是App和Extension，他们可以共用包中的framework。</p>
<p>列出所有动态链接的库：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">otool -L &lt;PathToArchive&gt;/Products/Applications/&lt;AppName&gt;.app/&lt;AppBinary&gt;</span><br></pre></td></tr></table></figure>
<figure>
<img src="https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/art/address_space2_2x.png" alt="图2 使用动态库的应用程序" /><figcaption aria-hidden="true">图2 使用动态库的应用程序</figcaption>
</figure>
<h2 id="区分">区分</h2>
<p>使用file命令输出对应的Mach-O信息：</p>
<p>静态库：current ar <strong>archive</strong> random library</p>
<p>动态库：<strong>dynamically linked shared library</strong></p>
<h2 id="性能差异">性能差异</h2>
<p>待定。</p>
<h2 id="framework">framework</h2>
<p>framework时一个有着特定结构的文件夹，里面包含各种共享的资源。如：静态库/动态库、头文件、模块信息和资源（例如storyboard、xib、图像文件和本地化字符串）。</p>
<p>其中framework里面的object file类型决定了其可用的资源：</p>
<p>静态库：只能使用其中的头文件、模块信息。</p>
<p>动态库：可全部使用，即除了头文件、模块信息，还能嵌入资源。</p>
<h3 id="集成方式">集成方式</h3>
<p>集成到App时有以下两个选项：</p>
<ul>
<li>Linked：仅链接。启动时链接则勾选，否则要运行时才链接则不勾选。</li>
<li>Embedded：拷贝到App包中的framework目录。</li>
</ul>
<p>对于静态库和动态库framework有不同的选择：</p>
<p>静态库：Linked。因为静态库已经拷贝到App的Executable Mach-O文件中，Embed是没意义的，虽然Xcode允许这样做。</p>
<p>动态库：Linked（iOS可选，macOS必选） + Embedded</p>
<h3 id="动态更新动态库">动态更新动态库</h3>
<p>这里的动态更新是针对于已编译的包的动态更新，不是运行时的动态更新。</p>
<p>首先对于iOS，上App Store的App是不允许动态更新动态库的，因为在iOS中使用动态库只能通过framework形式，而上App Store会进行签名，其中就包含对framework的哈希，即上架后，就不允许改变其framework。而动态更新framework的方式可以在in house和develop模式下使用。</p>
<p><a href="iOS%20利用%20Framework%20进行动态更新.md">iOS 利用 Framework 进行动态更新.md</a></p>
<h2 id="cocoapods中的使用">CocoaPods中的使用</h2>
<p>Podfile：</p>
<ul>
<li><code>use_frameworks!</code>：当前范围使用framework。可以指定动态库、静态库。
<ul>
<li><code>use_frameworks! :linkage =&gt; :dynamic</code></li>
<li><code>use_frameworks! :linkage =&gt; :static</code></li>
</ul></li>
</ul>
<p>Podspec：</p>
<ul>
<li><code>spec.static_framework = true</code>：当使用<code>use_frameworks!</code>标记时，使用静态库framework。</li>
<li>引用系统库：
<ul>
<li><code>spec.frameworks = 'QuartzCore', 'CoreData'</code></li>
<li><code>spec.libraries = 'xml2', 'z'</code></li>
</ul></li>
<li>引用外部库：
<ul>
<li><code>spec.vendored_frameworks = 'MyFramework.framework', 'TheirFramework.framework'</code></li>
<li><code>spec.vendored_libraries = 'libProj4.a', 'libJavaScriptCore.a'</code></li>
</ul></li>
</ul>
<h2 id="动态库巧用">动态库巧用</h2>
<h3 id="减少静态库的依赖拷贝">减少静态库的依赖拷贝</h3>
<p>通过前面我们知道可执文件（主程序或者动态库）在构建的链接阶段，<strong>遇到静态库，吸附进来；遇到动态库，打标记，彼此保持独立。</strong></p>
<p>正因为动态库是保持独立的，那么可以自定义一个动态库把依赖的静态库吸附进来。<strong>对外整体呈现的是动态库特性。其他的组件依赖我们自定义的动态库，由于隔离性的存在，不会出现问题。</strong></p>
<blockquote>
<p>这个思路在处理项目组件化的时候非常有用，尤其是在使用Swift的项目中。</p>
</blockquote>
<h3 id="处理静态库之间的符号冲突">处理静态库之间的符号冲突</h3>
<p>背景：需要知道，在打包IPA的时候，最终静态库会被连接到最终的那个可执行文件中。所以如果多个静态库拥有了相同的符号必定会产生符号冲突。</p>
<p>静态库的符号和动态库库符号可以隔离，进而避免了链接时产生的符号冲突。</p>
<blockquote>
<p>这一点在处理一些由于底层三方库源码不能手动修改（比如boringssl与openssl）的时候，非常有用。</p>
</blockquote>
<h2 id="参考-1">参考</h2>
<ul>
<li><a href="翻译-在应用程序中嵌入framework.md">翻译-在应用程序中嵌入framework.md</a></li>
<li><a href="年轻人，听说你想使用Framework.md">年轻人，听说你想使用Framework.md</a></li>
<li><a target="_blank" rel="noopener" href="https://www.jianshu.com/p/4e0fd0214152">iOS动态库、静态库及使用场景、方式 - 简书</a></li>
</ul>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/atom.xml">
            <span class="icon">
              <i class="fa fa-rss"></i>
            </span>

            <span class="label">RSS</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Apple/" rel="tag"># Apple</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/posts/extension_type_determination/" rel="prev" title="扩展名类型判断">
      <i class="fa fa-chevron-left"></i> 扩展名类型判断
    </a></div>
      <div class="post-nav-item">
    <a href="/posts/implement_multiple_proxies_using_object_wrappers/" rel="next" title="使用对象包装实现多代理">
      使用对象包装实现多代理 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          
    <div class="comments" id="gitalk-container"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#object-file"><span class="nav-text">Object File</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#macos%E6%94%AF%E6%8C%81%E7%9A%84%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%A0%BC%E5%BC%8F"><span class="nav-text">macOS支持的可执行格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%80%9A%E7%94%A8%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%A0%BC%E5%BC%8F"><span class="nav-text">通用二进制格式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#mach-o"><span class="nav-text">Mach-O</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%96%87%E4%BB%B6%E6%A0%BC%E5%BC%8F"><span class="nav-text">文件格式</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%82%E8%80%83"><span class="nav-text">参考</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%9D%99%E6%80%81%E5%BA%93"><span class="nav-text">静态库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9E%84%E5%BB%BA%E8%AE%BE%E7%BD%AE"><span class="nav-text">构建设置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8A%A8%E6%80%81%E5%BA%93"><span class="nav-text">动态库</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8C%BA%E5%88%86"><span class="nav-text">区分</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%80%A7%E8%83%BD%E5%B7%AE%E5%BC%82"><span class="nav-text">性能差异</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#framework"><span class="nav-text">framework</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%9B%86%E6%88%90%E6%96%B9%E5%BC%8F"><span class="nav-text">集成方式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8A%A8%E6%80%81%E6%9B%B4%E6%96%B0%E5%8A%A8%E6%80%81%E5%BA%93"><span class="nav-text">动态更新动态库</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#cocoapods%E4%B8%AD%E7%9A%84%E4%BD%BF%E7%94%A8"><span class="nav-text">CocoaPods中的使用</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8A%A8%E6%80%81%E5%BA%93%E5%B7%A7%E7%94%A8"><span class="nav-text">动态库巧用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%87%8F%E5%B0%91%E9%9D%99%E6%80%81%E5%BA%93%E7%9A%84%E4%BE%9D%E8%B5%96%E6%8B%B7%E8%B4%9D"><span class="nav-text">减少静态库的依赖拷贝</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A4%84%E7%90%86%E9%9D%99%E6%80%81%E5%BA%93%E4%B9%8B%E9%97%B4%E7%9A%84%E7%AC%A6%E5%8F%B7%E5%86%B2%E7%AA%81"><span class="nav-text">处理静态库之间的符号冲突</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E5%8F%82%E8%80%83-1"><span class="nav-text">参考</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="權咚"
      src="/images/icon.png">
  <p class="site-author-name" itemprop="name">權咚</p>
  <div class="site-description" itemprop="description">🤘🤯👾</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">84</span>
          <span class="site-state-item-name">文章</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">6</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">10</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/bqlin" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;bqlin" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://weibo.com/hearingdog" title="Weibo → https:&#x2F;&#x2F;weibo.com&#x2F;hearingdog" rel="noopener" target="_blank"><i class="fab fa-weibo fa-fw"></i>Weibo</a>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
      Links
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <a href="https://xiaozhuanlan.com/metal-reference-translation" title="https:&#x2F;&#x2F;xiaozhuanlan.com&#x2F;metal-reference-translation" rel="noopener" target="_blank">Metal内参</a>
        </li>
        <li class="links-of-blogroll-item">
          <a href="https://xiaozhuanlan.com/wwdc21" title="https:&#x2F;&#x2F;xiaozhuanlan.com&#x2F;wwdc21" rel="noopener" target="_blank">WWDC21 内参</a>
        </li>
    </ul>
  </div>

      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2016 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">權咚</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-area"></i>
    </span>
    <span title="站点总字数">279k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">4:14</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/pangu@4/dist/browser/pangu.min.js"></script>

<script src="/js/utils.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var canonicalURL, curProtocol;
      //Get the <link> tag
      var x=document.getElementsByTagName("link");
		//Find the last canonical URL
		if(x.length > 0){
			for (i=0;i<x.length;i++){
				if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
					canonicalURL=x[i].href;
				}
			}
		}
    //Get protocol
	    if (!canonicalURL){
	    	curProtocol = window.location.protocol.split(':')[0];
	    }
	    else{
	    	curProtocol = canonicalURL.split(':')[0];
	    }
      //Get current URL if the canonical URL does not exist
	    if (!canonicalURL) canonicalURL = window.location.href;
	    //Assign script content. Replace current URL with the canonical URL
      !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
  </script>




  
<script src="/js/local-search.js"></script>











<script>
if (document.querySelectorAll('pre.mermaid').length) {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/mermaid@8/dist/mermaid.min.js', () => {
    mermaid.initialize({
      theme    : 'default',
      logLevel : 3,
      flowchart: { curve     : 'linear' },
      gantt    : { axisFormat: '%m/%d/%Y' },
      sequence : { actorMargin: 50 }
    });
  }, window.mermaid);
}
</script>


  

  

  

<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.css">

<script>
NexT.utils.loadComments(document.querySelector('#gitalk-container'), () => {
  NexT.utils.getScript('//cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js', () => {
    var gitalk = new Gitalk({
      clientID    : '7ed324dbfd2741c35c0e',
      clientSecret: '75a59e1f6a55202c4a1b0ec3570ad5b5dccbc390',
      repo        : 'bqlin.github.io',
      owner       : 'bqlin',
      admin       : ['bqlin'],
      id          : '1de05b1d0bacbe27734c80fc400af5bb',
        language: 'zh-CN',
      distractionFreeMode: true
    });
    gitalk.render('gitalk-container');
  }, window.Gitalk);
});
</script>

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"debug":false,"model":{"scale":1,"jsonPath":"/live2dw/assets/hijiki.model.json"},"display":{"position":"right","vOffset":-100},"mobile":{"show":false,"scale":0.5},"log":false});</script></body>
</html>
